<html>
	<head>
	<link rel="stylesheet" type="text/css" href="style.css">
	<?php
		function readFiles($dir){
			$handle=opendir ($dir);
			$filesarray = array();

			while ($datei = readdir ($handle)) {
				if(substr($datei,-4) == ".txt")
					$filesarray[] = $datei; //Nimmt erste freie Stelle
			}

			closedir($handle);
			return $filesarray;
		}
	
		$letter = $_GET["letter"];
			if($letter == null) {
				?>
					<script type="text/javascript">
						window.location = "index.php";
					</script>
				<?php 
			}
		$author = $_GET["author"];
			if($author == null) {
				?>
					<script type="text/javascript">
						window.location = "index.php";
					</script>
				<?php 
			}
	?>
	<title><?php echo $author; ?></title>
	</head>

	<body>
		<script type="text/javascript" src="wz_tooltip.js"></script>
		<script type="text/javascript" src="sidebarLetters.js"></script>
		<div id="title">
			EBook-Reader
		</div>
		<div id="bar">
			<div id="sidebarLetters-close">
				<a onclick="javaScript: openLetters()"> ||| </a>
			</div>
			<div id="letterlist" isVisible="false">
				<?php
					echo "<a class='letter' href='index.php'>&nbsp; @ &nbsp;</a>";
					for($i = 1; $i <= 26; $i++){
						echo "<a class='letter";
						if($letter == chr(64 + $i)) echo "Cur";
						echo "' href='makelist.php?letter=";
						echo chr(64 + $i);
						echo "'>&nbsp; ";
						echo chr(64 + $i);
						echo " &nbsp;</a>";
					}
				?>
			</div>
		</div>
		<div id="content">
			<div id="mainlist">
				<?php echo "<p>Alle B&uuml;cher von $author</p>"?>
				<div id="booktbl">
					<?php
						$files = readFiles("./ebooks/" . $letter . "/");
					?>
					<!--<tr>-->		
					<?php
						$counter = 1;
						foreach($files as $file){
							if(strpos($file,$author) === false)
								continue;
							/*if($counter == 6){
								$counter = 1;
								echo "</tr>";
								echo "<tr height='200px'>";
							}*/
							$bookname = basename($file, ".txt");
							if(file_exists("./ebooks/" . $letter . "/" . $bookname . ".jpg"))
								$picfile = "./ebooks/" . $letter . "/" . $bookname . ".jpg";
							else
								$picfile = "./ebooks/nocover.jpg";
							$bookatts = explode("-", $bookname);	
							echo "<a href='show.php?letter=$letter&file=$file'><img class='bild' src='$picfile' alt='$bookname' onmouseover=\"Tip('&nbsp;$bookatts[0]&nbsp;<br />&nbsp;<br />&nbsp;$bookatts[1]&nbsp;')\" onmouseout=\"UnTip()\" /></a>";
							$counter++;
						}
						/*while($counter <= 5) {
							echo "<td>&nbsp;</td>";
							$counter++;
						} */
					?>
					</div>
				</div>
			</div>
		</body>
</html>